package com.ls.demo.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ls.demo.common.enums.RoleEnum;
import com.ls.demo.entity.Account;
import com.ls.demo.entity.Feedback;
import com.ls.demo.entity.Student;
import com.ls.demo.entity.Submit;
import com.ls.demo.mapper.SubmitMapper;
import com.ls.demo.utils.TokenUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SubmitService {
    @Resource
    private SubmitMapper  submitMapper;
    public void add(Submit submit) {
        Account currentUser = TokenUtils.getCurrentUser();
        submit.setStudentId(currentUser.getId());
        submit.setStatus("待审批");
        submit.setSubmitTime(DateUtil.now());
        submitMapper.insert(submit);
    }

    public void updateById(Submit submit){
        submitMapper.updateById(submit);
        submit.setStatus("已审批");
    }

    public void deleteById(Integer id) {
        submitMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            submitMapper.deleteById(id);
        }
    }

    public Submit selectById(Integer id) {
        return submitMapper.selectById(id);
    }

    public List<Submit> selectAll(Submit submit) {
        return submitMapper.selectAll(submit);
    }

    public PageInfo<Submit> selectPage(Submit submit, Integer pageNum, Integer pageSize) {
//        Account currentUser = TokenUtils.getCurrentUser();
//        if (RoleEnum.STUDENT.name().equals(currentUser.getRole())) {
//            submit.setStudentId(currentUser.getId());
//        }
        PageHelper.startPage(pageNum, pageSize);
        List<Submit> list = submitMapper.selectAll(submit);
        return PageInfo.of(list);
    }
    public PageInfo<Student> stuselectPage(Student student, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Student> list = submitMapper.stuselectAll(student);
        return PageInfo.of(list);
    }

    public PageInfo<Submit> showme(Submit submit, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Submit> list = submitMapper.showme(submit);
        return PageInfo.of(list);
    }

    public Student stuUpdate(Student student) {
        Student stu = submitMapper.stuUpdate(student);
        return stu;
    }
}
